package com.macro.mall.es.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.common.domain.DocQueryReq;
import com.macro.mall.common.dto.DocDelDto;
import com.macro.mall.common.dto.DocDto;
import com.macro.mall.common.dto.ProductEsDto;
import com.macro.mall.es.service.EsDocService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Es文档示例(MySQL的行)
 */
@RestController
@RequestMapping("/doc")
@Tag(name = "EsDocController", description = "Es文档示例接口")
public class EsDocController {
    @Autowired
    private EsDocService esDocService;

    /**
     * 批添
     * @param docDto
     * @return
     */
    @PostMapping("/batchSave")
    public CommonResult batchSave(@RequestBody DocDto docDto){
        esDocService.batchSave(docDto);
        return CommonResult.success("批量添加成功");
    }

    /**
     * 批删
     * @param docDelDto
     * @return
     */
    @DeleteMapping("/batchDelete")
    public CommonResult batchDelete(@RequestBody DocDelDto docDelDto){
        esDocService.batchDelete(docDelDto);
        return CommonResult.success("批删成功");
    }

    /**
     * 查询
     * @param docQueryReq
     * @return
     */
    @PostMapping("/search")
    public CommonResult<List<ProductEsDto>> search(@RequestBody DocQueryReq docQueryReq){
        List<ProductEsDto> search = esDocService.search(docQueryReq);
        return CommonResult.success(search);
    }
}








